﻿using CloudMusic.Helper;
using CloudMusic.Model;
using CloudMusic.View;
using CloudMusic.ViewModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Threading;

namespace CloudMusic.UC
{
    /// <summary>
    /// 音乐详情页面 的交互逻辑
    /// </summary>
    public partial class UCMusicDetail : UserControl
    {

        public UCMusicDetail()
        {
            InitializeComponent();
        }
        private void _share_Click(object sender, RoutedEventArgs e)
        {
            Detail_share.IsOpen = true;
            e.Handled = true;
        }
        /// <summary>
        /// 注册事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UCDetail_Loaded(object sender, RoutedEventArgs e)
        {
            MainWindowViewModel.UCEvent += MusicViewModelBase_UCEvent;
            MainWindowViewModel.PlayBtnCommdEvent += MainWindowViewModel_PlayBtnCommdEvent;
        }
        /// <summary>
        /// 播放按钮点击时候唱片/摇杆动画选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindowViewModel_PlayBtnCommdEvent(object sender, EventArgs e)
        {
            try
            {
                switch (sender.ToString())
                {
                    case "Pause":
                        imgNeedle.BeginStoryboard(FindResource("NeedleOff") as Storyboard);
                        rotate.BeginStoryboard(FindResource("CoverRotateOff") as Storyboard);
                        break;
                    case "Play":
                        MusicViewModelBase_UCEvent(sender, e);
                        break;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 唱片/摇杆动画开启
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MusicViewModelBase_UCEvent(object sender, EventArgs e)
        {
            try
            {
                imgNeedle.BeginStoryboard(FindResource("NeedleOn") as Storyboard);
                rotate.BeginStoryboard(FindResource("CoverRotateOn") as Storyboard);
            }
            catch (Exception)
            {

                throw;
            }

        }
        /// <summary>
        /// 阻止下一次的鼠标点击事件发生，以免连续触发pop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Detail_share_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }

        //private void storeBtn_Click(object sender, RoutedEventArgs e)
        //{
        //    UCStoreWin.ShowWin(Application.Current.MainWindow);
        //}
    }
}
